package com.intelligentmeterreadingsys.settingsys.activity;


import com.intelligentmeterreadingsys.R;
import com.intelligentmeterreadingsys.settingsys.db.SettingDao;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class SettingWebActivity extends Activity{

	 public Button button1;//确定按钮
	 
	 public EditText edit1;
	 public EditText edit2;
	
	 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
	
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.settingsys_web);
		init();
		
	}

	/**
	 * 初始化组件
	 */
	 public void init(){
		 button1=(Button)findViewById(R.id.setting_web_ok);
		 edit1=(EditText)findViewById(R.id.setting_web_id);
		 edit2=(EditText)findViewById(R.id.setting_web_port);
		
		 initDate();
		 button1.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
			   
				boolean b=add();
				if(b){
					Toast.makeText(SettingWebActivity.this, "操作成功", Toast.LENGTH_LONG).show();
				}else{
					Toast.makeText(SettingWebActivity.this, "操作失败", Toast.LENGTH_LONG).show();
					 initDate();
				}
			}
		});
	 }
	 
	 /**
	  * 添加数据
	  * @return
	  */
	 public boolean  add(){
		 SettingDao dao=new SettingDao(this);
	boolean b=	dao.saveWebSetting(edit1.getEditableText().toString(), "DownFile",
				          "WaterService", edit2.getEditableText().toString());
		 
		return b;
		 
	 }
	 
	 /**
	  * 初始化数据
	  */
	 public void initDate(){
		 
		 SettingDao dao=new SettingDao(this);
		String[] s= dao.queryWebSeting();
		edit1.setText(s[0]);
		edit2.setText(s[1]);
		
		
	 }
}
